/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ditt.outils;

/**
 *
 * @author attobra
 */
public class TestException {

    public static void main (String[] args){
        short test =50;
        javax.swing.JOptionPane.showMessageDialog(null, factoriel(21));
    }
    
    //Utilisation de la recursivité
    public static long factoriel(int n){
        
       try{     
            if(n>20){
                throw new java.lang.IllegalArgumentException(n+ " est trop grand");
                
            }else if(n > 1)
                return n*factoriel(n-1);
            else
                return 1;
            
         }catch(IllegalArgumentException ex){
             javax.swing.JOptionPane.showMessageDialog(null, ex.getMessage());
             System.exit(0);
             return 1;
        }
 
        
    }
    
    
    public static long factoriel(short n){
        long factoriel  = 1 ;
        if(n>1){
            for (int i=2; i<=n ; i++)
            factoriel *= i;
        }
        return factoriel;
 
        
    }
    
    
    
    
    
}
